var pageSize = 10;
var pageNum = 1;
var page;
var laypage;
var list;
var layer;
var index;


$(function () {
    $("#menuId").val(sessionStorage.menuId);
    // alert("000"+sessionStorage.menuId);
    layui.use(['laydate','element','laypage','layer'], function(){
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        element = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层

        //以上模块根据需要引入



        var start = {
            // min: laydate.now()
            max: '2099-06-16 23:59:59'
            ,istoday: true
            ,choose: function(datas){
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };

        var end = {
            // min: laydate.now()
            max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };

        document.getElementById('LAY_demorange_s').onclick = function(){
            start.elem = this;
            laydate(start);
        }
        document.getElementById('LAY_demorange_e').onclick = function(){
            end.elem = this
            laydate(end);
        }

    });
    setTimeout(function () {
        findConsumerMoneyCashFlow();
    },200);

});



//查询商铺列表
function findConsumerMoneyCashFlow(){
    var menuId = $("#menuId").val();
    var startTime = $("#LAY_demorange_s").val();
    var endTime = $("#LAY_demorange_e").val();
    var phone = $("#phone").val();

    var params = {
        "type":"query",
        "menuId":menuId,
        "pageSize":pageSize,
        "pageNum":pageNum,
        "phone":phone,
        "startTime":startTime,
        "endTime":endTime
    };
    $.ajax({
       type:"post",
       url: "/businessShop/consumerMoney",//findMerchantsList",
       data:params,
       dataType: "json",
       success : function(data){
            if(data.code == 1 && data.code != undefined && data.listVo.length != 0){
                list = data.listVo;
                page = data.page;
                var html = "";
                for(var b in list){
                    var title = list[b].title;
                    //1:广告币充值订单 2创客合伙人订单  3:消费金充值订单  4:优惠买单订单'
                    if(title == 1){
                        title = "广告币充值";
                    }else if(title == 2){
                        title = "创客合伙人";
                    }else if(title == 3){
                        title = "消费金充值";
                    }else if(title == 4){
                        title = "优惠买单";
                    }else{
                        title = "";
                    }

                    var role = list[b].userRole;
                    if(role == "HEHUOREN"){
                        role = "合伙人";
                    }else if(role == "CHUANG"){
                        role = "创客";
                    }else if(role == "SERVER"){
                        role = "服务商";
                    }else if(role == "SUPER"){
                        role = "管理员";
                    }else{
                        role = "普通用户";
                    }

                    html += '<tr><td>' + (list[b].userId == null ? "" : list[b].userId) + '</td>' +
                        '<td>' + (list[b].userPhone == null ? "" : list[b].userPhone) + '</td>' +
                        '<td>' + (list[b].receiveId == null ? "" : list[b].receiveId) + '</td>' +
                        '<td>' + (list[b].receivePhone == null ? "" : list[b].receivePhone) + '</td>' +
                        '<td>' + (list[b].consumerMoney == null ? "" : list[b].consumerMoney) + '</td>' +
                        '<td>' + (list[b].createTime == null ? "" : list[b].createTime) + '</td>' +
                        '<td>' + title + '</td>' +
                        '<td>' + (list[b].dealPrice == null ? "" : list[b].dealPrice) + '</td>' +
                        '<td>' + role + '</td>' +
                        '<td>' + (list[b].shopName == null ? "" : list[b].shopName) + '</td>';

                }
                $("#bus").html(html);
                $("#total").html("共有数据："+page.total+" 条");
                laypage({
                    cont: 'page'
                    ,pages: page.pages
                    ,first: 1
                    ,curr:pageNum
                    ,last: page.pages
                    ,prev: '<em><</em>'
                    ,next: '<em>></em>'
                    ,jump: function (obj,first) {
                        pageNum = obj.curr;
                        if(!first){
                            findConsumerMoneyCashFlow();
                        }
                    }
                });
            }else if(data == 9999 && data != undefined){
                window.location.href = "/login_toLogin";
            }else if(data == 1111 && data != undefined){
                alert("无权操作");
            }else {
                $("#bus").html("<tr><td colspan='10' style='font-size:20px;text-align: center'><span>无数据</span></td></tr>");
                $("#total").html("共有数据：0条");
                $("#page").html("");
            }
       }

    });
}
//条件查询
function ck(obj){
    //按钮样式切换
    if(obj.className == "layui-btn layui-btn-primary"){
        $(obj).attr("class","layui-btn layui-btn-normal");
        if(obj.id == "s1"){
            obj.value = 0;
        }else if(obj.id == "s2"){
            obj.value = 1;
        }else if(obj.id == "s3"){
            obj.value = 1;
        }
    }else {
        $(obj).attr("class","layui-btn layui-btn-primary");
        obj.value = "";
    }
    pageNum = 1;
    findConsumerMoneyCashFlow();
}

//查询按钮
function search() {
    pageNum = 1;
    findConsumerMoneyCashFlow();
}
